#--------------------------------#
cpu_num=`grep -c "processor" /proc/cpuinfo`; #CPU核数
netcard=`cat /proc/net/dev|sort -rn -k2|awk '{print $1}'|awk NR==1|awk -F ':' '{print $1}'`;#网卡名称
#--------------------------------#

for ((i=0;i<$cpu_num;i++))
do 
	sysctl -w kernel.sched_domain.cpu$i.domain0.flags=4671;
done #默认值为4655

#kernel.sched_domain.cpu0.domain0.flags = 4655
#其中4655的十六进制是0x11d6，这个值的含义是啥呢？
#在linux/sched/topology.h 中通过下面的值组合处理
#define SD_BALANCE_NEWIDLE	0x0001	/* Balance when about to become idle */
#define SD_BALANCE_EXEC		0x0002	/* Balance on exec */
#define SD_BALANCE_FORK		0x0004	/* Balance on fork, clone */
#define SD_BALANCE_WAKE		0x0008  /* Balance on wakeup */
#define SD_WAKE_AFFINE		0x0010	/* Wake task to waking CPU */
#define SD_ASYM_CPUCAPACITY	0x0020  /* Domain members have different CPU capacities */
#define SD_SHARE_CPUCAPACITY	0x0040	/* Domain members share CPU capacity */
#define SD_SHARE_POWERDOMAIN	0x0080	/* Domain members share power domain */
#define SD_SHARE_PKG_RESOURCES	0x0100	/* Domain members share CPU pkg resources */
#define SD_SERIALIZE		0x0200	/* Only a single load balancing instance */
#define SD_ASYM_PACKING		0x0400  /* Place busy groups earlier in the domain */
#define SD_PREFER_SIBLING	0x0800	/* Prefer to place tasks in a sibling domain */
#define SD_OVERLAP		0x1000	/* sched_domains of this level overlap */
#define SD_NUMA			0x2000	/* cross-node balancing */
 
#例如可以针对唤醒任务是考虑SD中的负载，选择负载低的cpu方式
#则可以设置这个flags为123F，则是下面这些的组合
#define SD_OVERLAP		0x1000	/* sched_domains of this level overlap *
#define SD_SERIALIZE		0x0200	/* Only a single load balancing instance */
#define SD_WAKE_AFFINE		0x0010	/* Wake task to waking CPU */
#define SD_ASYM_CPUCAPACITY	0x0020  /* Domain members have different CPU capacities */
#define SD_BALANCE_NEWIDLE	0x0001	/* Balance when about to become idle */
#define SD_BALANCE_EXEC		0x0002	/* Balance on exec */
#define SD_BALANCE_FORK		0x0004	/* Balance on fork, clone */
#define SD_BALANCE_WAKE		0x0008  /* Balance on wakeup */

sysctl -w  kernel.sched_child_runs_first = 0 #该变量表示在创建子进程的时候是否让子进程抢占父进程
sysctl -w  kernel.sched_min_granularity_ns = 3000000 #表示进程最少运行时间，防止频繁的切换，对于交互系统（如桌面），该值可以设置得较小，这样可以保证交互得到更快的响应（见周期调度器的check_preempt_tick过程）
sysctl -w  kernel.sched_latency_ns = 15000000 #表示一个运行队列所有进程运行一次的周期，当前这个与运行队列的进程数有关，如果进程数超过sched_nr_latency（这个变量不能通过/proc设置，它是由(sysctl_sched_latency+ sysctl_sched_min_granularity-1)/sysctl_sched_min_granularity确定的），那么调度周期就是sched_min_granularity_ns*运行队列里的进程数，与sysctl_sched_latency无关；否则队列进程数小于sched_nr_latency，运行周期就是sysctl_sched_latency。显然这个数越小，一个运行队列支持的sched_nr_latency越少，而且当sysctl_sched_min_granularity越小时能支持的sched_nr_latency越多，那么每个进程在这个周期内能执行的时间也就越少，这也与上面sysctl_sched_min_granularity变量的讨论一致。其实sched_nr_latency也可以当做我们cpu load的基准值，如果cpu的load大于这个值，那么说明cpu不够使用了
sysctl -w  kernel.sched_wakeup_granularity_ns = 3000000 #表示进程被唤醒后至少应该运行的时间的基数，它只是用来判断某个进程是否应该抢占当前进程，并不代表它能够执行的最小时间（sysctl_sched_min_granularity），如果这个数值越小，那么发生抢占的概率也就越高（见wakeup_gran、wakeup_preempt_entity函数）
sysctl -w  kernel.sched_features = 3183 #表示调度器支持的特性，如GENTLE_FAIR_SLEEPERS(平滑的补偿睡眠进程),START_DEBIT(新进程尽量的早调度),WAKEUP_PREEMPT(是否wakeup的进程可以去抢占当前运行的进程)等，所有的features见内核sech_features.h文件的定义
sysctl -w  kernel.sched_migration_cost = 500000 #判断一个进程是否还是hot，如果进程的运行时间（now - p->se.exec_start）小于它，那么内核认为它的code还在cache里，所以该进程还是hot，那么在迁移的时候就不会考虑它
sysctl -w  kernel.sched_nr_migrate = 32 #在多CPU情况下进行负载均衡时，一次最多移动多少个进程到另一个CPU上
sysctl -w  kernel.sched_time_avg = 1000
sysctl -w  kernel.sched_shares_window = 10000000
sysctl -w  kernel.timer_migration = 1
sysctl -w  kernel.sched_rt_period_us = 1000000 #该参数与sched_rt_runtime_us一起决定了实时进程在以sched_rt_period为周期的时间内，实时进程最多能够运行的总的时间不能超过sched_rt_runtime_us
sysctl -w  kernel.sched_rt_runtime_us = 950000 #该参数与sched_rt_period一起决定了实时进程在以sched_rt_period为周期的时间内，实时进程最多能够运行的总的时间不能超过sched_rt_runtime_us
sysctl -w  kernel.sched_compat_yield = 0
sysctl -w  kernel.sched_rr_timeslice_ms = 100 #用来指示round robin调度进程的间隔，这个间隔默认是100ms
sysctl -w  kernel.sched_autogroup_enabled = 0 #启用后，内核会创建任务组来优化桌面程序的调度。它将把占用大量资源的应用程序放在它们自己的任务组，这有助于性能提升

sysctl -w  kernel.sched_cfs_bandwidth_slice_us = 5000
sysctl -w  kernel.panic = 0
sysctl -w  kernel.exec-shield = 1
sysctl -w  kernel.core_uses_pid = 1
sysctl -w  kernel.core_pattern = core
sysctl -w  kernel.core_pipe_limit = 0
sysctl -w  kernel.tainted = 0
sysctl -w  kernel.real-root-dev = 0
sysctl -w  kernel.print-fatal-signals = 0
sysctl -w  kernel.ctrl-alt-del = 0
sysctl -w  kernel.ftrace_enabled = 1
sysctl -w  kernel.stack_tracer_enabled = 0
sysctl -w  kernel.ftrace_dump_on_oops = 0
sysctl -w  kernel.modprobe = /sbin/modprobe
sysctl -w  kernel.modules_disabled = 0
sysctl -w  kernel.kexec_load_disabled = 0
sysctl -w  kernel.hotplug =
sysctl -w  kernel.acct = 4    2    30
sysctl -w  kernel.sysrq = 0
sysctl -w  kernel.cad_pid = 1
sysctl -w  kernel.threads-max = 62803
sysctl -w  kernel.random.poolsize = 4096
sysctl -w  kernel.random.entropy_avail = 168
sysctl -w  kernel.random.read_wakeup_threshold = 64
sysctl -w  kernel.random.write_wakeup_threshold = 128
sysctl -w  kernel.random.boot_id = 3b7f0235-9995-4885-91ce-ea8f614896ac
sysctl -w  kernel.random.uuid = 349859da-0492-4b69-aaba-eef98ad0a663
sysctl -w  kernel.usermodehelper.bset = 4294967295    4294967295
sysctl -w  kernel.usermodehelper.inheritable = 4294967295    4294967295
sysctl -w  kernel.overflowuid = 65534
sysctl -w  kernel.overflowgid = 65534
sysctl -w  kernel.pid_max = 32768
sysctl -w  kernel.panic_on_oops = 1
sysctl -w  kernel.printk = 4    4    1    7
sysctl -w  kernel.printk_ratelimit = 5
sysctl -w  kernel.printk_ratelimit_burst = 10
sysctl -w  kernel.printk_delay = 0
sysctl -w  kernel.dmesg_restrict = 0
sysctl -w  kernel.kptr_restrict = 1
sysctl -w  kernel.ngroups_max = 65536
sysctl -w  kernel.cap_last_cap = 33
sysctl -w  kernel.watchdog = 1
sysctl -w  kernel.watchdog_thresh = 60
sysctl -w  kernel.softlockup_panic = 0 #设置产生softlockup时是否抛出一个panic。Softlockup用于检测CPU可以响应中断，但是在长时间内不能调度（比如禁止抢占时间太长）的死锁情况。这个机制运行在一个hrtimer的中断上下文，每隔一段时间检测一下是否发生了调度，如果过长时间没发生调度，说明系统被死锁。

 
sysctl -w  kernel.softlockup_all_cpu_backtrace = 0
sysctl -w  kernel.nmi_watchdog = 1 #使能nmi_watchdog
sysctl -w  kernel.unknown_nmi_panic = 0
sysctl -w  kernel.panic_on_unrecovered_nmi = 0
sysctl -w  kernel.panic_on_io_nmi = 0
sysctl -w  kernel.bootloader_type = 113
sysctl -w  kernel.bootloader_version = 1
sysctl -w  kernel.kstack_depth_to_print = 12
sysctl -w  kernel.io_delay_type = 0
sysctl -w  kernel.randomize_va_space = 2
sysctl -w  kernel.acpi_video_flags = 0
sysctl -w  kernel.hung_task_panic = 0
sysctl -w  kernel.hung_task_check_count = 4194304
sysctl -w  kernel.hung_task_timeout_secs = 120
sysctl -w  kernel.hung_task_warnings = 10
sysctl -w  kernel.compat-log = 1
sysctl -w  kernel.max_lock_depth = 1024
sysctl -w  kernel.poweroff_cmd = /sbin/poweroff
sysctl -w  kernel.keys.maxkeys = 200
sysctl -w  kernel.keys.maxbytes = 20000
sysctl -w  kernel.keys.root_maxkeys = 1000000
sysctl -w  kernel.keys.root_maxbytes = 25000000
sysctl -w  kernel.keys.gc_delay = 300
sysctl -w  kernel.slow-work.min-threads = 2
sysctl -w  kernel.slow-work.max-threads = 4
sysctl -w  kernel.slow-work.vslow-percentage = 50
sysctl -w  kernel.perf_event_paranoid = 1
sysctl -w  kernel.perf_event_mlock_kb = 516
sysctl -w  kernel.perf_event_max_sample_rate = 100000
sysctl -w  kernel.blk_iopoll = 1
sysctl -w  kernel.panic_on_warn = 0
sysctl -w  kernel.sched_domain.cpu0.domain0.min_interval = 1
sysctl -w  kernel.sched_domain.cpu0.domain0.max_interval = 4
sysctl -w  kernel.sched_domain.cpu0.domain0.busy_idx = 2
sysctl -w  kernel.sched_domain.cpu0.domain0.idle_idx = 0
sysctl -w  kernel.sched_domain.cpu0.domain0.newidle_idx = 0
sysctl -w  kernel.sched_domain.cpu0.domain0.wake_idx = 0
sysctl -w  kernel.sched_domain.cpu0.domain0.forkexec_idx = 0
sysctl -w  kernel.sched_domain.cpu0.domain0.busy_factor = 64
sysctl -w  kernel.sched_domain.cpu0.domain0.imbalance_pct = 125
sysctl -w  kernel.sched_domain.cpu0.domain0.cache_nice_tries = 1
sysctl -w  kernel.sched_domain.cpu0.domain0.flags = 4655
sysctl -w  kernel.sched_domain.cpu0.domain0.name = MC
sysctl -w  kernel.sched_domain.cpu1.domain0.min_interval = 1
sysctl -w  kernel.sched_domain.cpu1.domain0.max_interval = 4
sysctl -w  kernel.sched_domain.cpu1.domain0.busy_idx = 2
sysctl -w  kernel.sched_domain.cpu1.domain0.idle_idx = 0
sysctl -w  kernel.sched_domain.cpu1.domain0.newidle_idx = 0
sysctl -w  kernel.sched_domain.cpu1.domain0.wake_idx = 0
sysctl -w  kernel.sched_domain.cpu1.domain0.forkexec_idx = 0
sysctl -w  kernel.sched_domain.cpu1.domain0.busy_factor = 64
sysctl -w  kernel.sched_domain.cpu1.domain0.imbalance_pct = 125
sysctl -w  kernel.sched_domain.cpu1.domain0.cache_nice_tries = 1
sysctl -w  kernel.sched_domain.cpu1.domain0.flags = 4655
sysctl -w  kernel.sched_domain.cpu1.domain0.name = MC
sysctl -w  kernel.sched_domain.cpu2.domain0.min_interval = 1
sysctl -w  kernel.sched_domain.cpu2.domain0.max_interval = 4
sysctl -w  kernel.sched_domain.cpu2.domain0.busy_idx = 2
sysctl -w  kernel.sched_domain.cpu2.domain0.idle_idx = 0
sysctl -w  kernel.sched_domain.cpu2.domain0.newidle_idx = 0
sysctl -w  kernel.sched_domain.cpu2.domain0.wake_idx = 0
sysctl -w  kernel.sched_domain.cpu2.domain0.forkexec_idx = 0
sysctl -w  kernel.sched_domain.cpu2.domain0.busy_factor = 64
sysctl -w  kernel.sched_domain.cpu2.domain0.imbalance_pct = 125
sysctl -w  kernel.sched_domain.cpu2.domain0.cache_nice_tries = 1
sysctl -w  kernel.sched_domain.cpu2.domain0.flags = 4655
sysctl -w  kernel.sched_domain.cpu2.domain0.name = MC
sysctl -w  kernel.sched_domain.cpu3.domain0.min_interval = 1
sysctl -w  kernel.sched_domain.cpu3.domain0.max_interval = 4
sysctl -w  kernel.sched_domain.cpu3.domain0.busy_idx = 2
sysctl -w  kernel.sched_domain.cpu3.domain0.idle_idx = 0
sysctl -w  kernel.sched_domain.cpu3.domain0.newidle_idx = 0
sysctl -w  kernel.sched_domain.cpu3.domain0.wake_idx = 0
sysctl -w  kernel.sched_domain.cpu3.domain0.forkexec_idx = 0
sysctl -w  kernel.sched_domain.cpu3.domain0.busy_factor = 64
sysctl -w  kernel.sched_domain.cpu3.domain0.imbalance_pct = 125
sysctl -w  kernel.sched_domain.cpu3.domain0.cache_nice_tries = 1
sysctl -w  kernel.sched_domain.cpu3.domain0.flags = 4655
sysctl -w  kernel.sched_domain.cpu3.domain0.name = MC
sysctl -w  kernel.vsyscall64 = 1
sysctl -w  kernel.ostype = Linux
sysctl -w  kernel.osrelease = 2.6.32-573.22.1.el6.x86_64
sysctl -w  kernel.version = #1 SMP Wed Mar 23 03:35:39 UTC 2016
sysctl -w  kernel.hostname = ap-uce-uop-mq
sysctl -w  kernel.domainname = (none)
sysctl -w  kernel.pty.max = 4096
sysctl -w  kernel.pty.nr = 1
sysctl -w  kernel.shmmax = 68719476736
sysctl -w  kernel.shmall = 4294967296
sysctl -w  kernel.shmmni = 4096
sysctl -w  kernel.shm_rmid_forced = 0
sysctl -w  kernel.msgmax = 65536
sysctl -w  kernel.msgmni = 15737
sysctl -w  kernel.msgmnb = 65536
sysctl -w  kernel.sem = 250    32000    32    128
sysctl -w  kernel.auto_msgmni = 1
sysctl -w  vm.overcommit_memory = 0
sysctl -w  vm.panic_on_oom = 0
sysctl -w  vm.oom_kill_allocating_task = 0
sysctl -w  vm.extfrag_threshold = 500
sysctl -w  vm.oom_dump_tasks = 1
sysctl -w  vm.would_have_oomkilled = 0
sysctl -w  vm.overcommit_ratio = 50
sysctl -w  vm.overcommit_kbytes = 0
sysctl -w  vm.page-cluster = 3
sysctl -w  vm.dirty_background_ratio = 10
sysctl -w  vm.dirty_background_bytes = 0
sysctl -w  vm.dirty_ratio = 20
sysctl -w  vm.dirty_bytes = 0
sysctl -w  vm.dirty_writeback_centisecs = 500
sysctl -w  vm.dirty_expire_centisecs = 3000
sysctl -w  vm.nr_pdflush_threads = 0
sysctl -w  vm.swappiness = 0
sysctl -w  vm.nr_hugepages = 0
sysctl -w  vm.nr_hugepages_mempolicy = 0
sysctl -w  vm.hugetlb_shm_group = 0
sysctl -w  vm.hugepages_treat_as_movable = 0
sysctl -w  vm.nr_overcommit_hugepages = 0
sysctl -w  vm.lowmem_reserve_ratio = 256    256    32
sysctl -w  vm.drop_caches = 0
sysctl -w  vm.min_free_kbytes = 67584
sysctl -w  vm.extra_free_kbytes = 0
sysctl -w  vm.unmap_area_factor = 0
sysctl -w  vm.meminfo_legacy_layout = 1
sysctl -w  vm.percpu_pagelist_fraction = 0
sysctl -w  vm.max_map_count = 65530
sysctl -w  vm.laptop_mode = 0
sysctl -w  vm.block_dump = 0
sysctl -w  vm.vfs_cache_pressure = 100
sysctl -w  vm.legacy_va_layout = 0
sysctl -w  vm.zone_reclaim_mode = 0
sysctl -w  vm.min_unmapped_ratio = 1
sysctl -w  vm.min_slab_ratio = 5
sysctl -w  vm.stat_interval = 1
sysctl -w  vm.mmap_min_addr = 4096
sysctl -w  vm.numa_zonelist_order = default
sysctl -w  vm.scan_unevictable_pages = 0
sysctl -w  vm.memory_failure_early_kill = 0
sysctl -w  vm.memory_failure_recovery = 1
sysctl -w  vm.admin_reserve_kbytes = 8192
sysctl -w  fs.inode-nr = 43147    2072
sysctl -w  fs.inode-state = 43147    2072    0    0    0    0    0
sysctl -w  fs.file-nr = 736    0    798336
sysctl -w  fs.file-max = 798336
sysctl -w  fs.nr_open = 1048576
sysctl -w  fs.dentry-state = 43591    37426    45    0    0    0
sysctl -w  fs.overflowuid = 65534
sysctl -w  fs.overflowgid = 65534
sysctl -w  fs.leases-enable = 1
sysctl -w  fs.dir-notify-enable = 1
sysctl -w  fs.lease-break-time = 45
sysctl -w  fs.aio-nr = 0
sysctl -w  fs.aio-max-nr = 65536
sysctl -w  fs.inotify.max_user_instances = 128
sysctl -w  fs.inotify.max_user_watches = 8192
sysctl -w  fs.inotify.max_queued_events = 16384
sysctl -w  fs.epoll.max_user_watches = 1646346
sysctl -w  fs.suid_dumpable = 0
sysctl -w  fs.binfmt_misc.status = enabled
sysctl -w  fs.quota.lookups = 0
sysctl -w  fs.quota.drops = 0
sysctl -w  fs.quota.reads = 0
sysctl -w  fs.quota.writes = 0
sysctl -w  fs.quota.cache_hits = 0
sysctl -w  fs.quota.allocated_dquots = 0
sysctl -w  fs.quota.free_dquots = 0
sysctl -w  fs.quota.syncs = 2
sysctl -w  fs.quota.warnings = 1
sysctl -w  fs.mqueue.queues_max = 256
sysctl -w  fs.mqueue.msg_max = 10
sysctl -w  fs.mqueue.msgsize_max = 8192
sysctl -w  fs.mqueue.msg_default = 10
sysctl -w  fs.mqueue.msgsize_default = 8192
sysctl -w  fs.nfs.nlm_grace_period = 0
sysctl -w  fs.nfs.nlm_timeout = 10
sysctl -w  fs.nfs.nlm_udpport = 0
sysctl -w  fs.nfs.nlm_tcpport = 0
sysctl -w  fs.nfs.nsm_use_hostnames = 0
sysctl -w  fs.nfs.nsm_local_state = 0
sysctl -w  fs.nfs.nfs_callback_tcpport = 0
sysctl -w  fs.nfs.idmap_cache_timeout = 600
sysctl -w  fs.nfs.nfs_mountpoint_timeout = 500
sysctl -w  fs.nfs.nfs_congestion_kb = 90816
sysctl -w  debug.exception-trace = 1
sysctl -w  debug.kprobes-optimization = 1
sysctl -w  dev.scsi.logging_level = 0
sysctl -w  dev.raid.speed_limit_min = 1000
sysctl -w  dev.raid.speed_limit_max = 200000
sysctl -w  dev.hpet.max-user-freq = 64
sysctl -w  dev.mac_hid.mouse_button_emulation = 0
sysctl -w  dev.mac_hid.mouse_button2_keycode = 97
sysctl -w  dev.mac_hid.mouse_button3_keycode = 100
sysctl -w  dev.cdrom.info = CD-ROM information, Id: cdrom.c 3.20 2003/12/17
sysctl -w  dev.cdrom.info =
sysctl -w  dev.cdrom.info = drive name:        sr0
sysctl -w  dev.cdrom.info = drive speed:        4
sysctl -w  dev.cdrom.info = drive # of slots:    1
sysctl -w  dev.cdrom.info = Can close tray:        1
sysctl -w  dev.cdrom.info = Can open tray:        1
sysctl -w  dev.cdrom.info = Can lock tray:        1
sysctl -w  dev.cdrom.info = Can change speed:    1
sysctl -w  dev.cdrom.info = Can select disk:    0
sysctl -w  dev.cdrom.info = Can read multisession:    1
sysctl -w  dev.cdrom.info = Can read MCN:        1
sysctl -w  dev.cdrom.info = Reports media changed:    1
sysctl -w  dev.cdrom.info = Can play audio:        1
sysctl -w  dev.cdrom.info = Can write CD-R:        0
sysctl -w  dev.cdrom.info = Can write CD-RW:    0
sysctl -w  dev.cdrom.info = Can read DVD:        1
sysctl -w  dev.cdrom.info = Can write DVD-R:    0
sysctl -w  dev.cdrom.info = Can write DVD-RAM:    0
sysctl -w  dev.cdrom.info = Can read MRW:        1
sysctl -w  dev.cdrom.info = Can write MRW:        1
sysctl -w  dev.cdrom.info = Can write RAM:        1
sysctl -w  dev.cdrom.info =
sysctl -w  dev.cdrom.info =
sysctl -w  dev.cdrom.autoclose = 1
sysctl -w  dev.cdrom.autoeject = 0
sysctl -w  dev.cdrom.debug = 0
sysctl -w  dev.cdrom.lock = 1
sysctl -w  dev.cdrom.check_media = 0


sysctl -w  abi.vsyscall32 = 1
sysctl -w  crypto.fips_enabled = 0
sysctl -w  sunrpc.rpc_debug = 0
sysctl -w  sunrpc.nfs_debug = 0
sysctl -w  sunrpc.nfsd_debug = 0
sysctl -w  sunrpc.nlm_debug = 0
sysctl -w  sunrpc.transports = tcp 1048576
sysctl -w  sunrpc.transports = udp 32768
sysctl -w  sunrpc.transports = tcp-bc 1048576
sysctl -w  sunrpc.udp_slot_table_entries = 16
sysctl -w  sunrpc.tcp_slot_table_entries = 2
sysctl -w  sunrpc.tcp_max_slot_table_entries = 65536
sysctl -w  sunrpc.min_resvport = 665
sysctl -w  sunrpc.max_resvport = 1023
sysctl -w  sunrpc.tcp_fin_timeout = 15 #默认值是 60



